home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------
- Copyright 1995, Steve Israelson
-
- I own this code. You are free to use this code in any software
- you want. You may not sell this source code at all, you can
- sell your product though. If you want to include this code
- in any code collection (CD-Roms etc) this is OK as long as
- I get a complimentary copy.
- Steve.
-
- Holds a list of regular expression and matches them to an input
- string returning any parameters and the ID of the expression matched.
-
- Uses PowerPlants LList class, although any list class could
- be used with few changes.
- ---------------------------------------------------------------*/
- #include "StevesParser.h"
- #include "StevesRgExp.h"
-
-
- /*---------------------------------------------------------------
- Nothing to construct.
- ---------------------------------------------------------------*/
- MyParser::MyParser(void)
- {
- }
-
- /*---------------------------------------------------------------
- Delete all the expressions from the list.
- ---------------------------------------------------------------*/
- MyParser::~MyParser()
- {
- RegExp *theExpr;
- for (int x = 1; x <= expressions.GetCount(); ++x)
- if (expressions.FetchItemAt(x, &theExpr))
- delete theExpr;
- }
-
- /*---------------------------------------------------------------
- Pass in the text to be parsed and a list to hold any parameters
- that are found. Simply trys to match each regular expression
- and returns the expressions ID when it does.
- ---------------------------------------------------------------*/
- long MyParser::Parse(char *text, LList *params)
- {
- RegExp *theExpr;
- for (int x = 1; x <= expressions.GetCount(); ++x)
- {
- if (expressions.FetchItemAt(x, &theExpr))
- if (theExpr->Match(text, 0, nil, params))
- return theExpr->ID;
- }
- return 0; // no expressions matched
- }
-
- /*---------------------------------------------------------------
- Adds an expression to the expression list. You MUST add the
- more specific expressions first, and the more general last,
- since ".*a.*" will match anything with an "a" in it before
- something like "aardvark" will get matched, so put the ".*a.*"
- in this list last.
- ---------------------------------------------------------------*/
- void MyParser::AddExpression(char *text, long ID)
- {
- RegExp *theExpr = RegExp::Parse(text, nil, ID);
- if (theExpr)
- expressions.InsertItemsAt(1, arrayIndex_Last, &theExpr);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-